package com.fjec.activity.controller;

import com.fjec.activity.feign.MarketClient;
import com.fjec.activity.service.IBizGiveGiftService;
import com.fjec.activity.view.UserGiftVO;
import com.fjec.common.annotation.Json;
import com.fjec.common.protocol.JsonResult;
import com.fjec.common.shiro.AccountInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 002.赠送礼物表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-09-18
 */
@RestController
@RequestMapping("")
public class BizGiveGiftController {

    @Resource
    private IBizGiveGiftService service;

    @Autowired
    private MarketClient marketClient;
    // 发起礼物赠送
    @PostMapping("/y/givingGift/save")
    public JsonResult saveGivingGift(Long receId, String shopName, @Json List<UserGiftVO> gifts, String content) {
        int code = service.saveGivingGift(receId, shopName, gifts, content);
        if (code == -1)
            return JsonResult.failure().code("no gift").message("礼物不足").build();
        return JsonResult.SUCCESS;
    }

    // 领取礼物
    @PostMapping("/y/givingGift/receiveGift")
    public JsonResult receiveGift(Long givingId, Long busiId, Integer busiType) {
        Map<String, Object> result = service.receiveGift(givingId);
        marketClient.seckillAutoFollow(AccountInfo.getUserId(), busiId, busiType);
        return JsonResult.success().data(result).build();
    }

    @GetMapping("/y/givingGift/getMyGivingRecords")
    public JsonResult getMyGivingRecords() {
        Long userId = AccountInfo.getUserId();
        Integer busiType = AccountInfo.getBusiType();
        List<Map<String, Object>> result = service.getMyGivingRecords(userId, busiType);
        return JsonResult.success().data(result).build();
    }


}
